import { User } from "../models/user.model";
import { GlobalService } from "./global.service";

export class UserService {
  static PATH = '/user'

  static login(js_code: string) {
    return new Promise<User>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}/login`,
          method: "POST",
          data: {
            js_code
          },
          success: (response) => resolve(response.data as User),
          fail: (err) => reject(err)
        });
      }
    )
  }

  static updateUserInfo(user: User) {
    return new Promise<User>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}${UserService.PATH}`,
          method: "POST",
          data: user,
          success: (response) => resolve(response.data as User),
          fail: (err) => reject(err)
        });
      }
    )
  }
}
